<template>
	<view class="star">
		<SRV-topbar  title="小黄人急救：评论"></SRV-topbar>
		<view class="comment">
			<view class="item" v-for="(item,index) in pageResult.list" :key="index" @click="evaluateThis(index)">
				<view class="left">
				<SRV-profile :potos="item.head_portrait" :topicon="item.topicon" :srvhour="item.total_time" size="70"></SRV-profile>
				</view>
				<view class="right">
					<view class="txt">
						<view class="txt_con">
							<text><text>{{item.member_name}}</text></text>
							<text class="red" v-if="item.is_top==1">精选评论</text>
							<text class="yellow" v-if="item.is_summary==1">领队总结</text>
						</view>
						<text>{{item.create_time}}</text>
					</view>
					<view class="txt1">
						<text v-if="item.reply_member.member_id > 0">回复</text>
						<text v-if="item.reply_member.member_id > 0" class="name" @click="jump('home', item.reply_member.member_id)">{{item.reply_member.member_name}}</text>
						<text v-if="item.reply_member.member_id > 0">：</text>
						<text>{{item.content}}</text>
					</view>
					<view class="txt1">
						<view v-if="topUrl != '' && item.is_auth == 1 && item.is_top == 0" class="del_btn" @click="topEvaluate(index)">
							<uni-icons type="paperclip" size="15" color="#999" /> 精选
						</view>
						
						<view v-if="item.is_delete == 1" class="del_btn" @click="delEvaluate(index)">
							<uni-icons type="trash" size="15" color="#999" />删除
						</view>
						
					</view>
				</view>
			</view>
		</view>
		<view class="nocomment" v-if="pageResult.list.length == 0">
			暂无评价～
		</view>
		<view class="bottom">
			<view class="bottom_input">
				<input type="submit" value="" :placeholder="valplaceholder" v-model="content" ref="getFocus" id="inputId" />
				<text @click="evaluate()">发布</text>
			</view>
		</view>
		
		<footer-bar></footer-bar> 
		
	</view>
</template>

<script>
	var _self;
	import serve from '../../static/request.js';
	import storage from '../../static/appkey.js';
	import common from '../../static/jump.js';
	export default {
		data() {
			return {
				type: '',
				url: '',
				addUrl: '',
				delUrl: '',
				topUrl: '',
				pageParam: {
					appkey: uni.getStorageSync('appkey'),
					'access-token': uni.getStorageSync('access-token'),
					'local-city': uni.getStorageSync('localCity'),
					id:0,
					page: 0,
				},
				pageResult: {
					list: [],
					isEmpty: false,
					isEnd: false
				},
				content: "",
				valplaceholder:'说点什么吧～',
				evaluateId: 0,
			}
		},
		methods: {
			getList() {
				_self.pageParam.page ++;
				serve.request({
					url: _self.url,
					data: _self.pageParam
				}).then(res => {
					if(res.code == 200) {
						if (res.data && res.data.length > 0) {
							_self.pageResult.list = _self.pageResult.list.concat(res.data);
						}
						_self.pageResult.isEmpty = _self.pageResult.list.length == 0;
						_self.pageResult.isEnd = res.data.length == 0; 
					} else {
						uni.showToast({
							title:res.message,
						})
					}
				});
			},
			evaluate(){
				if(_self.content == "") {
					return ;
				}
				serve.request({
					url: _self.addUrl,
					data:{
						appkey: uni.getStorageSync('appkey'),
						'access-token': uni.getStorageSync('access-token'),
						'local-city': uni.getStorageSync('localCity'),
						id:_self.pageParam.id,
						content:_self.content,
						evaluate_id:_self.evaluateId,
					}
				}).then(res => {
					if(res.code != 200) {
						uni.showToast({
							title:res.message,
							icon: 'none',
						});
					}
					_self.content = '';
					_self.valplaceholder = "说点什么吧～";
					_self.evaluateId = 0;
					_self.pageParam.page = 0;
					_self.pageResult.list = [];
					_self.getList();
				});
			},
			evaluateThis(key){
				let item = _self.info.evaluate[key];
				_self.evaluateId = item.evaluate_id;
				let evaluate_member_name = item.member_name;
				_self.valplaceholder = "回复："+evaluate_member_name;
			},
			topEvaluate(key) {
				let evaluate_id = _self.pageResult.list[key].evaluate_id;
				uni.showModal({
				    title: '提示',
				    content: '您确定设置该评论为精选吗',
				    success: function (res) {
				        if (res.confirm) {
				            serve.request({
								url: _self.topUrl,
								data:{
									appkey: uni.getStorageSync('appkey'),
									'access-token': uni.getStorageSync('access-token'),
									id:evaluate_id,
								}
							}).then(res => {
								uni.showToast({
									title:res.message,
									icon: 'none',
									success: function() {
										if(res.code == 200) {
											_self.pageParam.page = 0;
											_self.pageResult.list = [];
											_self.getList();
										}
									}
								});
							});
				        } 
				    }
				});
			},
			delEvaluate(key){
				let evaluate_id = _self.info.evaluate[key].evaluate_id;
				uni.showModal({
				    title: '提示',
				    content: '您确定删除我的评论吗',
				    success: function (res) {
				        if (res.confirm) {
				            serve.request({
								url: _self.delUrl,
								data:{
									appkey: uni.getStorageSync('appkey'),
									'access-token': uni.getStorageSync('access-token'),
									id:evaluate_id,
								}
							}).then(res => {
								uni.showToast({
									title:res.message,
									icon: 'none'
								});
								if(res.code == 200) {
									_self.pageResult.list.splice(key,1);
								} 
							});
				        } 
				    }
				});
			},
			jump(jump_type, jump_link){
				common.jump(jump_type, jump_link);
			}
		},
		onLoad(options) {
			_self = this;
			_self.pageParam.id = options.id || 0;
			_self.type = options.type || 'medal';
			if(_self.type == 'medal') {
				_self.url = '/member/medal-evaluate/index';
				_self.addUrl = '/member/medal-evaluate/create';
				_self.delUrl = '/member/medal-evaluate/delete';
			} else if(_self.type == 'dynamic') {
				_self.url = '/dynamic/evaluate/index';
				_self.addUrl = '/dynamic/evaluate/create';
				_self.delUrl = '/dynamic/evaluate/delete';
				_self.topUrl = '/dynamic/evaluate/top'
			} else if(_self.type == 'article') {
				_self.url = '/article/evaluate/index';
				_self.addUrl = '/article/evaluate/create';
				_self.delUrl = '/article/evaluate/delete';
			} else if(_self.type == 'course') {
				_self.url = '/course/evaluate/index';
				_self.addUrl = '/course/evaluate/create';
				_self.delUrl = '/course/evaluate/delete';
			} else if(_self.type == 'activity') {
				_self.url = '/activity/evaluate/index';
				_self.addUrl = '/activity/evaluate/create';
				_self.delUrl = '/activity/evaluate/delete';
			} else if(_self.type == 'duty') {
				_self.url = '/member/duty/evaluate-list';
				_self.addUrl = '/member/duty/evaluate';
				_self.delUrl = '/member/duty/del-evaluate';
			}
			if(_self.pageParam.id == 0 || _self.url == '') {
				uni.showToast({
					title: "错误的访问方式",
					icon: 'none',
					success() {
						setTimeout(function () {
							common.jump('return_one');
						}, 1000) 
					}
				});
			}
			_self.pageParam.page = 0;
			_self.pageResult.list = [];
			_self.getList();
		},
		onPullDownRefresh() {
			_self.content = '';
			_self.valplaceholder = "说点什么吧～";
			_self.evaluateId = 0;
			_self.pageParam.page = 0;
			_self.pageResult.list = [];
			_self.getList();
		},
		onReachBottom() {
			console.log('触底'); 
			if(_self.pageResult.isEnd || _self.pageResult.isEmpty){
				return
			}
			_self.getList()
		}
	}
</script>

<style scoped lang="scss">
	.star {
		padding-bottom: 140upx;
		.comment {
			padding-top: 48upx;
			margin-left: 27upx;
		
			.title {
				font-size: 24upx;
				font-family: Microsoft YaHei UI;
				font-weight: bold;
			}
		
			.item:last-child {
				border-bottom: none
			}
		
			.item {
				padding: 41upx 0upx;
				display: flex;
				border-bottom: 1upx rgba(57, 72, 107, 0.1) solid;
		
				.left {
					image {
						width: 60upx;
						height: 60upx;
						border-radius: 50%;
					}
				}
		
				.right {
					margin-left: 13upx;
					width: 625upx;
		
					.txt {
						display: flex;
						justify-content: space-between;
						align-items: center;
						font-size: 28upx;
						font-weight: bold;
		
						.txt_con {
							display: flex;
							align-items: center;
		
							.red {
								border-radius: 15upx;
								padding: 2upx 12upx;
								font-size: 18upx;
								color: #FFFFFF;
								background: rgba(95, 162, 220, 1.0);
								margin-left: 15upx;
							}
		
							.yellow {
								border-radius: 15upx;
								padding: 2upx 12upx;
								font-size: 18upx;
								color: #FFFFFF;
								background: #FFC80A;
								margin-left: 15upx;
							}
						}
		
						text:last-child {
							color: rgba(60, 72, 104, 0.5);
							font-size: 20upx;
							font-weight: 400;
						}
					}
		
					.txt1 {
						color: #8F96A9;
						font-size: 28upx;
						margin-top: 30upx;
		
						.name {
							font-weight: bold;
							color: #3C4868;
						}
		
						.del_btn {
							//font-weight: bold;
							float: right;
							font-size: 22upx;
							margin: 10upx 20upx;
							color: #999;
							uni-icons{
								margin-right: 5upx;
							}
						}
					}
				}
			}
		
		}
		.bottom {
		
			width: calc(100% - 0upx);
			height: 150upx;
			padding: 0upx 30upx 30upx 30upx;
		
			position: fixed;
			left: 0;
			bottom: 0;
		
			display: flex;
			justify-content: space-between;
			align-items: center;
		
		
		
			border-top: 1upx #eee solid;
			box-sizing: border-box;
			background: #f0f0f0;
		
			.bottom_input{
				display: flex;
				input {
					width: 500upx;
					height: 60upx;
					background: rgba(60, 72, 104, 0.1);
					border-radius: 32upx;
					font-size: 26upx;
					padding-left: 50upx;
				}
				text{
					line-height: 60upx;
					margin-left: 20upx;
				}
			}
		
			
		}
		.nocomment {
			font-size: 28upx;
			color: rgba(60, 72, 104, 0.5);
			width: 100%;
			padding: 87upx 0upx;
			text-align: center;
		}
	}
</style>
